package com.zk.shop.servlet.reply;

import com.zk.shop.dao.GoodsDao;
import com.zk.shop.entity.Goods;
import com.zk.shop.entity.Msg;
import com.zk.shop.entity.Reply;
import com.zk.shop.entity.User;
import com.zk.shop.service.Impl.ReplyServiceImpl;
import com.zk.shop.service.ReplyService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("AddReplyServlet")
public class AddReplyServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ReplyService replyService = new ReplyServiceImpl();
        Reply reply = new Reply();
        User user = new User();
        Goods goods = new Goods();
        Msg msg = new Msg();
        int msgid =  Integer.parseInt(request.getParameter("msgid"));
        user.setUserId(3);
        goods.setGoodsId(1);
        msg.setMsgId(msgid);
        String content = request.getParameter("ReplyContent");

        reply.setConTent(content);
        reply.setUser(user);
        reply.setGoods(goods);
        reply.setMsg(msg);
        PrintWriter out=response.getWriter();
        if (content!=""){int flag =   replyService.addReply(reply);
            out.print(true);
        }else {
            System.out.println("回复内容为空，不能添加！");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
